<?php
/**
 * jishupu-cms
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2022/3/16
 */

namespace App\Http\Controllers;

use App\Services\AdsService;
use App\Services\InfoCategoryService;
use App\Services\InfoService;
use App\Services\LinksService;
use App\Services\MetaService;

/**
 * 首页
 * Class IndexController
 * @package App\Http\Controllers
 */
class IndexController extends Controller
{
    /**
     * 首页
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
     */
    function index()
    {
        $data = [];
        $data['meta'] = MetaService::siteMeta();
        $data['swiper_ads'] = AdsService::getAdsBySpaceId(1, 5); // 轮播
        $data['about_ads'] = AdsService::getAdsBySpaceId(2, 3); // 关于我们优势广告
        $data['services'] = InfoCategoryService::getAllSubsTreeByParentId(17);// 我们的服务列表
        // 客户案例
        $data['cases'] = InfoService::getList(function ($query) {
            $casesCateIds = InfoCategoryService::getSubIdsByParentId(13);
            $query->whereIn('info_category_id', $casesCateIds);
            $query->where('info_model_id', 2);
            $query->whereRaw('FIND_IN_SET(?,recommend_type)', '4'); // 首页推荐:4
        }, 12);
        // 轮播新闻
        $data['swiper_news'] = InfoService::getList(function ($query) {
            $newsCateIds = InfoCategoryService::getSubIdsByParentId(3);
            $query->whereIn('info_category_id', $newsCateIds);
            $query->where('cover_image', '<>', 0);
        }, 5);
        // 新闻
        $data['news'] = InfoService::getList(function ($query) {
            $newsCateIds = InfoCategoryService::getSubIdsByParentId(3);
            $query->whereIn('info_category_id', $newsCateIds);
        }, 4, ' top desc ');
        $data['links'] = LinksService::getList(); // 合作伙伴（友情链接）
        return $this->view('index', $data);
    }
}
